﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Web;
using Rhino.Mocks;

namespace YABETests
{
    // Thanx to Scott Hanselman
    public static class MockRepositoryExtension
    {
        public static HttpContextBase FakeHttpContext(this MockRepository mocks)
        {
            var context = mocks.PartialMock<HttpContextBase>();
            var request = mocks.PartialMock<HttpRequestBase>();
            var response = mocks.PartialMock<HttpResponseBase>();
            var session = mocks.PartialMock<HttpSessionStateBase>();
            var server = mocks.PartialMock<HttpServerUtilityBase>();

        //    var form = new NameValueCollection();
      //      var querystring = new NameValueCollection();

            SetupResult.For(context.Request).Return(request);
            SetupResult.For(context.Response).Return(response);
            SetupResult.For(context.Session).Return(session);
            SetupResult.For(context.Server).Return(server);
      //      SetupResult.For(context.Request.Form).Return(form);
     //       SetupResult.For(context.Request.QueryString).Return(querystring);

            mocks.Replay(context);
            return context;
        }

        public static HttpContextBase HttpContextFactory(this MockRepository mockery, string url)
        {
            HttpContextBase httpContext = mockery.Stub<HttpContextBase>();
            HttpRequestBase httpRequest = mockery.Stub<HttpRequestBase>();
            SetupResult.For(httpRequest.AppRelativeCurrentExecutionFilePath).Return("~" + url);
            SetupResult.For(httpContext.Request).Return(httpRequest);
            return httpContext;
        }
    }
}
